package com.gba.mark.origin.controller;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gba.mark.group.service.IGroupService;
import com.gba.mark.origin.service.IOriginService;
import com.gba.mark.user.entity.permission.UserRole;
import com.gba.mark.user.mapper.permission.UserRoleMapper;
import com.gba.mark.user.service.user.IUserService;
import com.gba.mark.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/origin")
public class OriginController {


    @Autowired
    private IUserService userService;

    @Autowired
    private IGroupService groupService;

    @Autowired
    private IOriginService originService;

    @Autowired
    private UserRoleMapper userRoleMapper;

    @GetMapping("/getOrigin")
    public ResponseUtil<JSONObject> getOrigin(Authentication authentication,
                                              @RequestParam String groupName){
        Integer userId = userService.getUserIdByAuth(authentication);
        Integer groupId = groupService.getGroupIdByAuthAndName(authentication, groupName);

        return originService.getOrigin(userId,groupId);

        //return new ResponseUtil<>(HttpStatus.OK, "",originService.getOrigin(userId,groupId));
    }

    @GetMapping("/skip")
    public ResponseUtil<JSONObject> skip (Authentication authentication,
                                          @RequestParam String groupName){
        Integer userId = userService.getUserIdByAuth(authentication);
        Integer groupId = groupService.getGroupIdByAuthAndName(authentication, groupName);

        return  originService.skip(userId,groupId);
      // return new ResponseUtil<>(HttpStatus.OK,"",originService.skip(userId,groupId));


    }

    @PostMapping("/deleteOrigin")
    public ResponseUtil<Boolean> deleteOrigin(Authentication authentication,
                                @RequestParam String groupName,
                                @RequestParam int originId){
        int userId = userService.getUserIdByAuth(authentication);
        int groupId = groupService.getGroupIdByAuthAndName(authentication, groupName);
        return new ResponseUtil<> (HttpStatus.OK, "",originService.deleteOrigin(userId, groupId, originId));

    }
}
